package analyzemytime.reports;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import analyzemytime.datamodel.Employee;
import analyzemytime.datamodel.Project;
import analyzemytime.datamodel.Report;

public class WeeklyEmployeeReport{
	
	private List<Report> reportList;
	Employee employee;
	String month;
	String year;
	Map<Project,Double> weeklyEmployeeReportMap;

	
	public void generateWeeklyEmployeeReport()
	{
		for(Report report: reportList)//Employee employee,Project project,String date, double reportedTime
		{
			if(report.getEmployee().getFirstName() == employee.getFirstName() && report.getEmployee().getLastName() == employee.getLastName())//if we have the employee we're looking for	
			{
				if(report.getDate().getYear() == Integer.parseInt(year))//if we have the year we're looking for
				{
					if(report.getDate().getMonthOfYear() == Integer.parseInt(month))//if we have the month we're looking for
					{
						Project key = report.getProject();
						Double value = report.getTimeReported();
						if(!weeklyEmployeeReportMap.containsKey(key))
						{
							weeklyEmployeeReportMap.put(key,value);
						}
						else
						{
							weeklyEmployeeReportMap.put(key,weeklyEmployeeReportMap.get(key)+value);//previous value + current value
						}
					}
				}
			}
		}
	}
	
	public void printMonthlyEmployeeReportToConsole()
	{
		System.out.println("Employee: "+employee.getFirstName()+" "+employee.getLastName()+" Month: "+month+" Year: "+year);
		System.out.println("Project | hours");
		Iterator<Project> monthlyEmployeeReportIterator=weeklyEmployeeReportMap.keySet().iterator();//this iterator needs to be created each time we want to print something out in the console!
		while(monthlyEmployeeReportIterator.hasNext())
		{
			Project project=monthlyEmployeeReportIterator.next();
			System.out.println(project.toString()+"    "+weeklyEmployeeReportMap.get(project));
		}	
	}
	
	//TODO
	public void printMonthlyEmployeeReportToFile()
	{
		
	}
	
	//TODO
	public void drawMonthlyEmployeeReportGraph()
	{
		
	}
	
	public List<Report> getReportList() {
		return reportList;
	}

	public void setReportList(List<Report> reportList) {
		this.reportList = reportList;
	}
}
